using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaterQualityReportSystem.models;

namespace WaterQualityReportSystem.utils
{
    public class ExcelHelper
    {
        public static void AppendDataToCsv(string filePath, ItemData itemdata)
        {
            string splitChar = ",";
            DateTime dtNow = DateTime.Now;
            bool shouldWriteHeader = false;
            if (File.Exists(filePath) == false)
            {
                shouldWriteHeader = true;
            }
            // 打开文件或创建新文件
            using (StreamWriter writer = new StreamWriter(filePath, true))
            {
                if (shouldWriteHeader)
                {
                    writer.WriteLine("上报时间" + splitChar + "设备ID" + splitChar + "检测项目" + splitChar + "单位" + splitChar + "浓度" + splitChar + "吸光" + splitChar + "透光" + splitChar + "测试日期" + splitChar + "测试时间" + splitChar + "原始数据");
                }
                // 写入数据
                writer.Write(dtNow.ToString("yyyy-MM-dd HH:mm:ss") + splitChar);
                writer.Write(itemdata.DeviceID + splitChar);
                writer.Write(itemdata.Name + splitChar);
                writer.Write(itemdata.Unit + splitChar);
                writer.Write(itemdata.Concentration + splitChar);
                writer.Write(itemdata.Absorbancy + splitChar);
                writer.Write(itemdata.Transparency + splitChar);
                writer.Write(itemdata.TestDate.ToString("yyyy-MM-dd") + splitChar);
                writer.Write(itemdata.TestDate.ToString("HH:mm:ss") + splitChar);
                writer.WriteLine(itemdata.hexDatas);
            }
        }

        //读取CSv文件，并解析其中的数据到DTO

    }
}

